<?php
require_once 'lib/controller.php';
require_once 'db/SubmitPersonDB.php';
require_once 'views/SubmitPersonView.php';
require_once '../../models/EmailModel.php';
require_once 'models/SubmitPersonModel.php';
require_once 'db/AlertsCheckDB.php';
require_once 'views/AlertsCheckView.php';
require_once 'models/AlertsCheckModel.php';

header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // Date in the past

$submitPersonDB = new SubmitPersonDB($db);
$submitPersonView = new SubmitPersonView($html);
$submitPersonEmailModel = new EmailModel();
$submitPersonModel = new SubmitPersonModel($submitPersonDB, $submitPersonView, $submitPersonEmailModel);
$alertsCheckDB = new AlertsCheckDB($db);
$alertsCheckView = new AlertsCheckView($html);
$alertsCheckEmailModel = new EmailModel();
$alertsCheckModel = new AlertsCheckModel($alertsCheckDB, $alertsCheckView, $alertsCheckEmailModel, $helper);

$lastName = $helper->post("surname");
$firstName = $helper->post("firstname");
$formerName = $helper->post("formername");
$neeName = $helper->post("neename");
$alsoKnownAs = $helper->post("alsoknownas");
$deathDate = $helper->post("deathdate");
$birthDate = $helper->post("birthdate");
$age = $helper->post("age");
$ageMeasure = $helper->post("agemeasure");
$cityTown = $helper->post("citytown");
$formerCityTown = $helper->post("formercitytown");
$region = $helper->post("region");
$country = $helper->post("country");
$charity = $helper->post('charity');
$funeralHomeId = intval($helper->post("funeralhome"));
$otherNotes = $helper->post("othernotes");
if(!empty($lastName)) {
    $personId = $submitPersonModel->addPerson($lastName, $firstName, $formerName, $neeName, $alsoKnownAs, $deathDate, $birthDate, $age, $ageMeasure, $cityTown, $formerCityTown, $region, $country, $charity, $funeralHomeId, $otherNotes);
    echo $personId;
    $submitPersonModel->sendEmail($funeralHomeId, $personId, $firstName, $lastName);
    $alertsCheckModel->check($personId);
}
?>